package View;

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JPanel;

public class GridPanel extends JPanel{
	private static final long serialVersionUID = 1L;
	private int chessw,chessh,left,top;
	
public GridPanel() {
	setOpaque(false);
}
@Override
public void paint(Graphics g) {
	
	super.paint(g);
	Graphics2D g2=(Graphics2D) g;//转换为2d		
	Composite composite=g2.getComposite();
	g2.setColor(new Color(0xB2DFEE));
	g2.setComposite(AlphaComposite.SrcOver.derive(0.6f));
	g2.fillRect(0, 0, getWidth(), getHeight());
	g2.setComposite(composite);
	drawGrid(g2);	
	drawChess(g2);
	
}

private void drawChess(Graphics2D g2) {
	// TODO Auto-generated method stub
	
}
private void drawGrid(Graphics2D g2) {
	int width=getWidth();
	int height=getHeight();
	chessw=width/15;
	chessh=height/15;
	left=width%15/2;
	top=height%15/2;
	int x=left+chessw/2,y=top+chessh/2;
	g2.setColor(Color.black);
	for(int i=0;i<15;i++){
		g2.drawLine(x+i*chessw, y, x+i*chessw,height-y );
		g2.drawLine(x, y+i*chessh, width-x, y+i*chessh);
	}
}
}